import axios from 'axios'
import Api from './api/index.js'
import useUserStore from '@/stores/user.js'

const userStore = useUserStore()

const instance = axios.create({
  timeout: 60000,
  baseURL: window.domain_config.gateway_server,
})

instance.interceptors.request.use(async (config) => {
  config.headers['Authorization'] = 'Bearer ' + (await userStore.getToken())
  return config
})

instance.interceptors.response.use((res) => {
  return Promise.resolve(res.data)
})

export default new Api(instance).use()
